package com.ywu.boot.log;

import ch.qos.logback.classic.pattern.ClassicConverter;
import ch.qos.logback.classic.spi.ILoggingEvent;
import com.ywu.boot.context.YwuContext;
import com.ywu.boot.context.YwuContextHolder;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;

import java.util.Objects;

/**
 * @ClassName YwuLogConvertor
 * @Description TODO
 * @Author GroundDemo
 * @Date 2024/3/10 14:45
 * @Version 1.0
 **/
public class YwuLogConvertor extends ClassicConverter {
    @Override
    public String convert(ILoggingEvent event) {
        YwuContext currentContext = YwuContextHolder.getCurrentContext();
        if (Objects.isNull(currentContext)) {
            return "[,]";
        }
        String traceId = currentContext.getYwuContextRequest().getTraceId();
        String spanId = currentContext.getYwuContextRequest().getSpanId();
        return "[" + traceId + ", " + spanId + "]";
    }
}
